package com.example.yu.slidebottomlayout_demo;

import android.support.constraint.ConstraintLayout;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;



public class MainActivityListAdapter extends RecyclerView.Adapter<MainActivityListAdapter.ViewHolder>   {

    public MainActivityListAdapter() {
    }

    /**
     * 创建视图
     * @param parent
     * @param viewType
     * @return
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
        return new ViewHolder(inflate);
    }

    /**
     * 绑定视图
     * @param holder
     * @param position
     */
    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(holder.background.getContext(), "click:中奖了" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 20;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private  ConstraintLayout background;

        public ViewHolder(View itemView) {
            super(itemView);
            background = itemView.findViewById(R.id.item_top);
        }
    }
}